package cn.iocoder.yudao.module.jifenyuan.dal.mysql.room;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
import cn.iocoder.yudao.module.jifenyuan.controller.app.roomuserbind.vo.AppRoomUserBindPageReqVO;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.room.RoomDO;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.room.RoomWithUsersDo;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.roomuserbind.RoomUserBindDO;
import cn.iocoder.yudao.module.jifenyuan.enums.JifenyuanRoomStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.jifenyuan.controller.app.room.vo.*;

/**
 * 记分员 房间 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface RoomMapper extends BaseMapperX<RoomDO> {

    default PageResult<RoomDO> selectPage(AppRoomPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RoomDO>()
                .likeIfPresent(RoomDO::getRoomName, reqVO.getRoomName())
                .eqIfPresent(RoomDO::getLeaderId, reqVO.getLeaderId())
                .eqIfPresent(RoomDO::getInviteCode, reqVO.getInviteCode())
                .eqIfPresent(RoomDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(RoomDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(RoomDO::getObserverCode, reqVO.getObserverCode())
                .eqIfPresent(RoomDO::getType, reqVO.getType())
                .orderByDesc(RoomDO::getId));
    }

    default List<RoomDO> selectList(AppRoomExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RoomDO>()
                .likeIfPresent(RoomDO::getRoomName, reqVO.getRoomName())
                .eqIfPresent(RoomDO::getLeaderId, reqVO.getLeaderId())
                .eqIfPresent(RoomDO::getInviteCode, reqVO.getInviteCode())
                .eqIfPresent(RoomDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(RoomDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(RoomDO::getObserverCode, reqVO.getObserverCode())
                .eqIfPresent(RoomDO::getType, reqVO.getType())
                .orderByDesc(RoomDO::getId));
    }
   default RoomDO getLiveRoomByLeaderId(Long userId){
       return selectOne(new LambdaQueryWrapper<RoomDO>().eq(RoomDO::getLeaderId,userId)
               .eq(RoomDO::getStatus, JifenyuanRoomStatusEnum.ENABLE.getStatus()));
   }

    default RoomDO selectOnlineRoomByObserverCode(String observerCode){
        return selectOne(new LambdaQueryWrapper<RoomDO>().eq(RoomDO::getObserverCode,observerCode)
                .eq(RoomDO::getStatus, JifenyuanRoomStatusEnum.ENABLE.getStatus()));
    }
    default RoomDO selectOnlineRoomByShareCode(String shareCode){
        return selectOne(new LambdaQueryWrapper<RoomDO>().eq(RoomDO::getInviteCode,shareCode)
                .eq(RoomDO::getStatus, JifenyuanRoomStatusEnum.ENABLE.getStatus()));
    }

    IPage<RoomWithUsersDo> selectRoomWithUserId(AppRoomUserBindPageReqVO reqVO);
}
